package LuoGu.贪心.分组;

import java.util.Arrays;
import java.util.Scanner;

public class Main_fail {
    //在某些情况下，重复而又又顺序的队员能力值会将能连续的代码块阻塞，若直接排序后用滑动窗口解决则会发生错误，例“1 1 1 2 2 2”
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int [] temp = new int [n+1];
        for(int i=0;i<n;i++){
            temp[i] = s.nextInt();
        }
        Arrays.sort(temp,0,n);
        int min = Integer.MAX_VALUE;
        int l = 0;
        int r = 1;
        while(r<=n){
            if(temp[r]!=temp[r-1]+1){
                min = Math.min(min,r-l);
                l = r;
                r++;
            }else{
                r++;
            }
        }System.out.print(min);
    }
}
